package org.soarsky.wealthchengdu.google.map;


import android.graphics.Rect;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;





public class OverlayItemPoint extends OverlayItem{
	private static final int size = 5;
	//private MarkExtend markExtend;
	private PointItemOverlays overlays = null;
	private boolean change = false;
	private Drawable marker = null;
	private int orlWidth=0,orlHeight=0;
	public OverlayItemPoint(GeoPoint point, String title, String snippet,
			PointItemOverlays overlays) {
		super(point, title, snippet);
		// TODO Auto-generated constructor stub
		this.overlays = overlays;
	}
	//public MarkExtend getMarkExtend() {
	//	return markExtend;
	//}
	//public void setMarkInfo(MarkExtend markExtend) {
	//	this.markExtend = markExtend;
	//}
	@Override
	public void setMarker(Drawable marker) {
		// TODO Auto-generated method stub
		this.marker =marker;
		if( orlWidth==0&&orlHeight==0){
			Rect rect = marker.getBounds();
			orlWidth=rect.width();
			orlHeight=rect.height();
		}
		
		
		super.setMarker(marker);
	}
	public Drawable getMarker(int stateBitset) {
		// TODO Auto-generated method stub
		OverlayItem focusedItem = overlays.getFocus();
		if(marker==null)return null;
		Rect rect = marker.getBounds();
		change = rect.width()>orlWidth&&rect.height()>orlHeight;
		if (focusedItem == null) {
			if(change){
				reSetRect( rect,change=false);
			}
			OverlayItem.setState(marker, 0);
			return marker;
		}
		if (focusedItem.equals(this)){
			if(change){
				//reSetRect( rect,change = false);
			}else{
				reSetRect( rect,change=true);	
			}
			OverlayItem.setState(marker, 2);
		}else{
			if(change){
				overlays.setDrawableSizeChange(false);
				reSetRect( rect,change=false);
				
			}
			OverlayItem.setState(marker, 0);
		}
		return marker;
	}
	
	private void reSetRect(Rect rect,boolean on){
	
		if(on){
			rect.left=rect.left>0?rect.left+size:rect.left-size;
			rect.top=rect.top>0?rect.top+size*2:rect.top-size*2;
			rect.right=rect.right>0?rect.right+size:rect.right-size;
		}else {
			rect.left=rect.left>0?rect.left-size:rect.left+size;
			rect.top=rect.top>0?rect.top-size*2:rect.top+size*2;
			rect.right=rect.right>0?rect.right-size:rect.right+size;
		}
	}
	
}
